<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../assets/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../assets/css/admin.css" />		
	</head>
	<body>
		<div style="margin: 30px;">
			<form class="layui-form" action="" method="post" onsubmit="return false;">
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red">*</span>菜单名称</label>
					<div class="layui-input-block">
						<input type="text" name="name" id="name" 
							   autocomplete="off" placeholder="请输菜单名称" class="layui-input" required>
					</div>
					<input type="hidden" name="id" id="id">
					<input type="hidden" name="editType" id="editType">
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red">*</span>上级菜单</label>
					<div class="layui-input-block">
						<select name="parentId" id="parentId" required><option value="">请选择</option></select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red">*</span>访问地址</label>
					<div class="layui-input-block">
						<input type="text" name="href" id="href" 
							   autocomplete="off" placeholder="请输访问地址" class="layui-input" required>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span style="color: red">*</span>菜单描述</label>
					<div class="layui-input-block">
						<textarea name="remarks" id="remarks"  placeholder="请输入描述内容" 
						class="layui-textarea" required></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="../../js/common/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../../assets/layui/layui.js"></script>
		<script type="text/javascript" src="../../js/common/formUtil.js"></script>
		<script type="text/javascript" src="../../js/common/commonUtil.js"></script>
		<script type="text/javascript">
		 layui.config({
				base: '../../assets/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index','layer','form'], function() {
				var $ = layui.jquery,
					layer = layui.layer,
				    form = layui.form;
				var parentId = "";
				if (!ComUtil.isEmpty($("#id").val())) {
					ComUtil.AjaxData(".layui-form",path + "/a/sys/MenuAction/queryMenuById.do", function(obj, data) {
						FromEngine.jsonBindForm(obj, data.data);
						if(data.data){
							parentId = data.data.parentId;
						}
					}, {
						menuId : $("#id").val()
					});
				}
				
				ComUtil.AjaxData("#parentId", path + "/a/sys/MenuAction/queryMenusByPid.do", 
						function(obj, data) {
							$("#parentId").empty();
							var data = data.data;
							var html = '<option value="">请选择</option>';
							if(parentId == '0'){
								html += '<option value="0" selected="selected">根目录</option>'
							}else{
								html += '<option value="0" >根目录</option>'
							}
							if(data.length>0){
								for (var i = 0; i < data.length; i++) {
									var obj = data[i]
									if(obj.id==parentId){
										html += '<option value="' + obj.id + '" selected="selected">' + obj.name
										+ '</option>'
									}else{
										html += '<option value="' + obj.id + '">' + obj.name
										+ '</option>'
									}
									
								}
							}
							
							$("#parentId").append(html);
							form.render("select");
					})
				FromEngine.vsFrom(".layui-form", {
					debug : false,
					beforeSubmitFunction:function(){
						$("#editType").val("<%=type%>");
						return true;
					},
					cfgUrlOrFunction : path + "/a/sys/MenuAction/saveMenu.do",
					cfgCallBack : function(result) {
						ComUtil.closeParentLayer(function() {
						});
					}
				});
			})
		</script>
		
	</body>	
</html>